CXX=g++# sets C++ compiler to g++
#CXXOPTIONS=-O0 -pipe -g -std=c++11 -Wno-unused-result -Wno-narrowing -Wno-format# -Wall sets C++ compile time options
CXXOPTIONS=-O0 -c -pipe -g3 -std=c++11 -Wno-unused-result -Wno-narrowing -Wno-format -pthread# -Wall sets C++ compile time options
CXXOPTIONS_RELEASE=-O3 -c -pipe -std=c++11 -pthread -funroll-loops -UDEBUG -UDEBUG_PRINT# -Wall sets C++ compile time options
CXXLIBS=#-lhdf5 -lcrypto# -lboost_regex# sets C++ libraries
CXXSOURCES=src/zletimer.cpp src/zlecmp.cpp #src/hdf5access.cpp# sets C++, C and CUDA source files
OUTPUTOBJECT=cudasqueeze-zle.o
OUTPUTFILE=cudasqueeze-zle
GPROF=#-pg #messes valgrind stats
DATAFILENAME=data/15mb.dump

NVCC=nvcc
NVCCOPTIONS_DEBUG=-g -G -O0 -c
NVCCOPTIONS=-g -G -O0 -c
NVCCOPTIONS_RELEASE=-O3 -c -UDEBUG -UDEBUG_PRINT
NVLOPTIONS=#-lhdf5 -lcrypto
CUDAOBJECT=cudasqueeze-zle-kernels.o

#CFLAGS = -g -O0 `sdl-config --cflags --libs`
#LDFLAGS= -lGL -lGLU -lglut -lpthread  -lSDL_mixer -lGLEW -lcuda
#NVFLAGS = -g -G -O0

#all: clean debug run
all: clean release run

Debug: debug

Release: release

release: 
	$(CXX) $(CXXOPTIONS_RELEASE) src/cudasqueeze-zle.cpp $(CXXSOURCES) $(CXXLIBS)
	$(NVCC) $(NVCCOPTIONS_RELEASE) src/cudasqueeze-zle-kernels.cu $(CUDAOBJECT)
	$(NVCC) -o $(OUTPUTFILE).release $(CXXLIBS) -Xcompiler ./*.o
	cp $(OUTPUTFILE).release $(OUTPUTFILE)


clang-anal:
	clang++ --analyze $(CXXOPTIONS) $(GPROF) src/cudasqueeze-zle.cpp -o $(OUTPUTFILE) $(CXXSOURCES) $(CXXLIBS)

cuda: #cudasqueeze-zle-kernels.o 
	$(NVCC) $(NVCCOPTIONS) src/cudasqueeze-zle-kernels.cu $(CUDAOBJECT)

host:
	$(CXX) $(CXXOPTIONS) $(GPROF) src/cudasqueeze-zle.cpp $(CXXSOURCES) $(CXXLIBS)

debug: host cuda
	$(NVCC) -o $(OUTPUTFILE) $(CXXLIBS) -Xcompiler ./*.o

clean:
	rm -f ./$(OUTPUTFILE) ./*.{dmp,o,so} *.out

run:
	touch decompressed.out compressed.out
	./$(OUTPUTFILE) $(DATAFILENAME) 2
	ls -al $(DATAFILENAME) decompressed.out compressed.out 
#	sha256sum $(DATAFILENAME) decompressed.out compressed.out | sort 
	
#	./$(OUTPUTFILE) /home/hstrauss/code/data/ska/1369858495.h5 # 15MB
#	./$(OUTPUTFILE) /home/hstrauss/code/data/ska/1369853370.h5 # 859MB
#	./$(OUTPUTFILE) /home/hstrauss/code/data/ska/1370279050.h5 # 2562MB
#	./$(OUTPUTFILE) /home/hstrauss/code/data/ska/1370418341.h5 # 4111MB
	
# h5dump -b LE  -d /Data/correlator_data -o 859mb.dump ~/code/data/ska/859mb.h5
